import { SystemConstant } from "@/types/enum";
import { UserInfoVo } from "@/types/login";
/**
 * 设置jwt
 * @param data
 */
export const setJwt = (data: string): void => {
  localStorage.setItem(SystemConstant.JWT, data);
};
/**
 * 获取jwt
 * @returns
 */
export const getJwt = (): string => {
  const jwt = localStorage.getItem(SystemConstant.JWT) || "";
  return jwt;
};
/**
 * 删除jwt
 */
export const removeJwt = (): void => {
  localStorage.removeItem(SystemConstant.JWT);
};
/**
 * 设置jwt
 * @param data
 */
export const setUserCache = (data: UserInfoVo): void => {
  const str = data ? JSON.stringify(data) : "";
  localStorage.setItem(SystemConstant.USER_INFO, str);
};
/**
 * 获取jwt
 * @returns
 */
export const getUserCache = (): UserInfoVo => {
  const str = localStorage.getItem(SystemConstant.USER_INFO) || "";
  const data = str ? JSON.parse(str) : {};
  return data;
};
/**
 * 删除jwt
 */
export const removeUserCache = (): void => {
  localStorage.removeItem(SystemConstant.USER_INFO);
};
/**
 * 清空缓存
 */
export const clearStorage = (): void => {
  localStorage.clear();
};
